﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;


using Jungle.Code.Utils;
using Jungle.Code.Core;

namespace Jungle.Alex.WebControls
{
    public class TopTabs : WebControl
    {
        // ------------------------------------------------------------------------------------------------------
        protected override void RenderContents(HtmlTextWriter writer)
        {
            string[] urls = { "", "/ru/main.aspx", "/ru/offers.aspx?cmd=comm", "/ru/tabthird.aspx", "/ru/tabfour.aspx" };
            if (Context.Request.RawUrl.IndexOf("/ru.aspx") != -1)
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Href, UrlHelper.GetSiteUrl() + urls[1]);
                writer.RenderBeginTag(HtmlTextWriterTag.A);
                PrintImage(writer, "/App_Themes/alex/img/bat/1on.gif");
                writer.RenderEndTag();

                writer.AddAttribute(HtmlTextWriterAttribute.Href, UrlHelper.GetSiteUrl() + urls[2]);
                writer.RenderBeginTag(HtmlTextWriterTag.A);
                PrintImage(writer, "/App_Themes/alex/img/bat/2out.gif");
                writer.RenderEndTag();

                writer.AddAttribute(HtmlTextWriterAttribute.Href, UrlHelper.GetSiteUrl() + urls[3]);
                writer.RenderBeginTag(HtmlTextWriterTag.A);
                PrintImage(writer, "/App_Themes/alex/img/bat/3out.gif");
                writer.RenderEndTag();

                writer.AddAttribute(HtmlTextWriterAttribute.Href, UrlHelper.GetSiteUrl() + urls[4]);
                writer.RenderBeginTag(HtmlTextWriterTag.A);
                PrintImage(writer, "/App_Themes/alex/img/bat/4out.gif");
                writer.RenderEndTag();
            }
            else
            {
                for (int i = 1; i <= 4; i++)
                {
                    writer.AddAttribute(HtmlTextWriterAttribute.Href, UrlHelper.GetSiteUrl() + urls[i]);
                    writer.RenderBeginTag(HtmlTextWriterTag.A);

                    if (Context.Request.RawUrl.IndexOf(urls[i]) != -1)
                        PrintImage(writer, "/App_Themes/alex/img/bat/" + i.ToString() + "on.gif");
                    else
                        PrintImage(writer, "/App_Themes/alex/img/bat/" + i.ToString() + "out.gif");

                    writer.RenderEndTag();
                }
            }
            base.RenderContents(writer);
        }
        // ------------------------------------------------------------------------------------------------------
        private HtmlTextWriter PrintImage(HtmlTextWriter writer, string imgUrl)
        {
            writer.AddAttribute(HtmlTextWriterAttribute.Src, UrlHelper.GetSiteUrl() + imgUrl);
            writer.AddAttribute(HtmlTextWriterAttribute.Align, "absmiddle");
            writer.RenderBeginTag(HtmlTextWriterTag.Img);
            writer.RenderEndTag();
            return writer;
        }
        // ------------------------------------------------------------------------------------------------------
    }
}
